package com.unitechs.trap.excel.webapi.service.impl.updata;

import com.unitechs.trap.common.pojo.trap.entity.UpdateDescr;
import com.unitechs.trap.common.pojo.trap.entity.UpdateDescrVO;
import com.unitechs.trap.excel.service.IUpdateAlarmtypeService;
import com.unitechs.trap.excel.webapi.mapper.AllDataMapper;
import com.unitechs.trap.excel.webapi.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.beans.Transient;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class UpdateAlarmtypeServiceImpl implements IUpdateAlarmtypeService {

    @Autowired
    private AllDataMapper allDataMapper;

    /**
     * 将Descr的英文数据更新为desc的中文数据
     */
    @Override
    @Transactional
    public void updateDescr() {
        List<UpdateDescr> list = allDataMapper.listDescr();
        for (UpdateDescr descr : list) {
            if (StringUtils.containsChinese(descr.getAlarmtypeDescr())) {
                continue;
            }
            if (null == descr.getTrapTypeDesc()) {
                continue;
            }
            String alarmtypeDesc = descr.getTrapTypeDesc().substring(3);
            allDataMapper.updateDescrByDesc(descr.getTrapOid(), alarmtypeDesc);

        }
    }

    /**
     * 展示英文的Descr
     * @return
     */
    @Override
    public UpdateDescrVO listEngDescr() {
        List<UpdateDescr> list = allDataMapper.listDescr();
        List<UpdateDescr> updateDescrs=new ArrayList<>();
        UpdateDescrVO updateDescrVO=new UpdateDescrVO();
        for (UpdateDescr descr:list){
            if (StringUtils.containsChinese(descr.getAlarmtypeDescr())){continue;}
            updateDescrs.add(descr);
        }
        updateDescrVO.setDescrs(updateDescrs);
        updateDescrVO.setCount(updateDescrs.size());
        return updateDescrVO;
    }




}
